<template>
  <div>
    <el-container>
      <el-header>
        <i class="el-icon-arrow-left"></i>
        hhh
      </el-header>
      <el-main>
        <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" label-width="80px" class="demo-ruleForm"
                 label-position="left">

          <el-form-item  label="转出账户">
            <el-input type="text" v-model="selectAccountId" auto-complete="off" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="收款户名" >
            <el-input type="password" v-model="toName" auto-complete="off" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="收款账号" >
            <el-input type="password" v-model="toCount" auto-complete="off" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="收款银行" >
            <el-input v-model="toBank" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="汇款金额" >
            <el-input v-model="toMoney" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="收款附言">
            <el-input v-model="comment" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="验证码" prop="yzm">
            <el-input v-model="ruleForm2.yzm"></el-input>
          </el-form-item>

          <el-form-item >
            <span v-show="!show" class="count">{{count}} s</span>
            <el-button type="primary" v-show="show"  @click="getCode">获取验证码</el-button>
            <el-button type="primary" @click="submitForm('ruleForm2')">提交</el-button>
          </el-form-item>
        </el-form>
      </el-main>
    </el-container>
  </div>
</template>

<script>
  import {mapState} from 'vuex'

  export default {
    data() {
      var checkmyAccount = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请选择账户'));
        } else {
          callback();
        }
      };
      var checktoName = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请选择账户'));
        } else {
          callback();
        }
      };
      var checktoCount = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请选择账户'));
        } else {
          callback();
        }
      };
      var checktoBank = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请选择账户'));
        } else {
          callback();
        }
      };
      var checktoMoney = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请选择账户'));
        } else {
          callback();
        }
      };
      var checkYZM=(rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入验证码'));
        } else if (value!=='5211314'){
          return callback(new Error('验证码不正确'));
        }else {
          callback();
        }
      };

      return {
        ruleForm2: {
          myAccount: '',
          toName: '',
          toCount: '',
          toBank: '',
          toMoney: '',
          comment: '',
          yzm: ''
        },
        rules2: {
          myAccount: [
            {validator: checkmyAccount, trigger: 'blur'}
          ],
          toName: [
            {validator: checktoName, trigger: 'blur'}
          ],
          toCount: [
            {validator: checktoCount, trigger: 'blur'}
          ],
          toBank: [
            {validator: checktoBank, trigger: 'blur'}
          ],
          toMoney: [
            {validator: checktoMoney, trigger: 'blur'}
          ],
          yzm:[
            {validator: checkYZM, trigger: 'blur'}
          ]
        },
        show: true,
        count: '',
        timer: null,
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$router.push('/TransferResult')
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      getCode(){
        alert('5211314');
        const TIME_COUNT = 60;
        if (!this.timer) {
          this.count = TIME_COUNT;
          this.show = false;
          this.timer = setInterval(() => {
            if (this.count > 0 && this.count <= TIME_COUNT) {
              this.count--;
            } else {
              this.show = true;
              clearInterval(this.timer);
              this.timer = null;
            }
          }, 1000)
        }
      }
    },
    computed:{
      ...mapState(['myAccount','selectAccountId','toName','toCount','toBank','toMoney','comment'])
    }
  }
</script>

<style scoped>
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
  }

  .el-icon-arrow-left {
    color: #fff;
    position: relative;
    top: 0px;
    left: -130px;
    font-size: 20px;
  }
</style>
